using System;

namespace Lyh.Train.Common.Convertor
{
	public class JsFuncitonHelper
	{
		public static string Escape(string str)
		{
			string codeBody = "function GetEscape(str){return escape(str);};";
			ScriptEngine scriptEngine = new ScriptEngine(ScriptLanguage.JavaScript);
			object obj = scriptEngine.Run("GetEscape", new object[]
			{
				str
			}, codeBody);
			return obj.ToString();
		}
		public static string GetJsTime(string timeStr)
		{
			string codeBody = "function GetJsTime(timeStr){var currentDate=new Date(timeStr);return currentDate+'';}";
			ScriptEngine scriptEngine = new ScriptEngine(ScriptLanguage.JavaScript);
			object obj = scriptEngine.Run("GetJsTime", new object[]
			{
				timeStr
			}, codeBody);
			return obj.ToString();
		}
		public static string GetCnt(string ticket, string seatType)
		{
			string codeBody = "function A(F,E){rt='';seat_1=-1;seat_2=-1;i=0;while(i<F.length){s=F.substr(i,10);c_seat=s.substr(0,1);if(c_seat==E){count=s.substr(6,4);while(count.length>1&&count.substr(0,1)=='0'){count=count.substr(1,count.length)}count=parseInt(count);if(count<3000){seat_1=count}else{seat_2=(count-3000)}}i=i+10}if(seat_1>-1){rt+=seat_1}if(seat_2>-1){rt+=','+seat_2}return rt}";
			ScriptEngine scriptEngine = new ScriptEngine(ScriptLanguage.JavaScript);
			object obj = scriptEngine.Run("A", new object[]
			{
				ticket,
				seatType
			}, codeBody);
			return obj.ToString();
		}
	}
}
